import request from '@/utils/request'

// 获取access_token
export function getAccessTokenAPI() {
  return request({
    url: '/wenxinapi/oauth/2.0/token',
    headers: {
      Accept: 'application/json',
      'Content-Type': 'application/json',
    },
    params: {
      client_id: 'fT4A2FlFWYqlBO5lMbMo38zj',
      client_secret: 'zaotgxtuuD25aYZXoPnB3TXkfHmcK9MF',
      grant_type: 'client_credentials',
    },
    method: 'POST',
  })
}

// 聊天
export async function chatAPI(data) {
  // console.log('发送请求之前的data为' + JSON.stringify(data))
  const response = await getAccessTokenAPI() as any
  return request({
    url: '/wenxinapi/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions',
    headers: { 'Content-Type': 'application/json' },
    params: {
      access_token:`${response.access_token}`
        // '24.b4fea0c53e068642a42fb34c835c6d94.2592000.1734349984.282335-116270900',
    },
    method: 'POST',
    data,
  })
}
